﻿<?php require_once('../Connections/STN.php'); ?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && true) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "login.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) 
  $MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?php include('componentes/enviafoto.class.php') ?>

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$idalbum=$_GET['album'];

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

//cadastro de fotos
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {


for($i=1;$i<6;$i++){
//verificação do campo
//o ["name"] e para pega o nome do arquivo

if($_FILES["arquivo$i"]["name"] != ""){
 
 
  $insertSQL = sprintf("INSERT INTO tb_fotos (FOT_ALB_CODIGO) VALUES (%s)",
                       GetSQLValueString($idalbum, "int"));

  mysql_select_db($database_STN, $STN);
  $Result1 = mysql_query($insertSQL, $STN) or die(mysql_error());
  
  
//pega o codigo da foto
	$query_pegafoto = "SELECT FOT_CODIGO from tb_fotos order by FOT_CODIGO desc LIMIT 1;";
	$RSpegafoto = mysql_query($query_pegafoto,$STN) or die(mysql_error());
	$totalLinhas_RSpegafoto = mysql_num_rows($RSpegafoto);
	$linha_RSpegafoto= mysql_fetch_assoc($RSpegafoto);
	
	
	$idfoto = $linha_RSpegafoto['FOT_CODIGO'];
  
//enviador de foto
  	$resultadofoto = enviafoto("arquivo$i","/imagem.jpg","fotosantiga",800,600,1,"$idfoto");

}

}
header ("location:fotos-lista.php?album=$idalbum");
}


//mostra as fotos do album
mysql_select_db($database_STN, $STN);
$query_RSfotos = "SELECT fot.*, alb.* FROM tb_albuns alb LEFT JOIN tb_fotos fot ON(fot.FOT_ALB_CODIGO=alb.ALB_CODIGO) where fot.FOT_ALB_CODIGO='$idalbum' or alb.ALB_CODIGO ='$idalbum'";
$RSfotos = mysql_query($query_RSfotos, $STN) or die(mysql_error());
$row_RSfotos = mysql_fetch_assoc($RSfotos);
$totalRows_RSfotos = mysql_num_rows($RSfotos);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <link  href="css/admin.css" rel="stylesheet" type="text/css" />
<title>Adiministrador</title>
</head>
<body>
<div id="main">
<div id="header">
            <a href="#" class="logo"><img src="img/logo.gif" width="101" height="29" alt="" /></a>
            <ul id="top-navigation">
            	<li><a href="index.php">INDEX</a></li>
                <li><a href="postagem-lista.php">POSTAGENS</a></li>
                <li><a href="arquivos-lista.php">ARQUIVOS</a></li>
                <li><a href="album-lista.php"class="active">FOTOS ANTIGAS</a></li>
                <li><a href="videos-lista.php">VIDEOS</a></li>
            </ul>
			<div class="logout">
        	<a href="logout.php"><img src="img/logout.png" /></a>
            </div>
        </div>
        <div id="middle">
<div id="left-column">
                <h3>FOTOS</h3>
                <br />              
                <a href="album-altera.php?album=<?php echo $idalbum ?>" class="link">EDITAR ÁLBUM</a>
                <a href="fotos-apaga.php?album=<?php echo $idalbum ?>" class="link1">APAGAR TODAS<br /> AS FOTOS</a>
            </div>
            <div id="center-column">
                <div class="top-bar">
                    <h1><?php echo $row_RSfotos['ALB_TITULO']; ?></h1>
                </div>
<div class="table">
<div style="text-align:center">

<div class="table">
	<table class="listing">
		<tr>
        	<th>TÍTULO:</th>
        	<td><?php echo $row_RSfotos['ALB_TITULO'] ?></td>
        </tr>
        <tr>
        	<th>ANO DO ÁLBUM:</th>
        	<td><?php echo $row_RSfotos['ALB_ANO_FOTOS'] ?></td>
        </tr>
        <tr>
        	<th valign="top">COMENTARIO:</th>
        	<td><?php echo $row_RSfotos['ALB_COMENTARIO'] ?></td>
        </tr>
        <tr>
        	<td colspan="2"><input type="button" onclick="document.location ='album-altera.php?album=<?php echo $idalbum ?>'" value="Editar" /></td>        
        </tr>

	</table>
</div>
<h5>Cadastra fotos</h5>
<!--formulario para cadastra as fotos-->
<form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="form1" id="form1">
  <table align="center">

    <tr>
      <td><label for="arquivo1">SELECIONE AS FOTOS</label></td>
      <td>
      <input type="file" name="arquivo1" id="arquivo1" value="" /></td>
    </tr>
      <tr>
      <td><label for="arquivo2">&nbsp;</label></td>
      <td>
      <input type="file" name="arquivo2" id="arquivo2" value="" /></td>
    </tr>
      <tr>
      <td><label for="arquivo3">&nbsp;</label></td>
      <td>
      <input type="file" name="arquivo3" id="arquivo3" value="" /></td>
    </tr>
      <tr>
      <td><label for="arquivo4">&nbsp;</label></td>
      <td>
      <input type="file" name="arquivo4" id="arquivo4" value="" /></td>
    </tr>
      <tr>
      <td><label for="arquivo5">&nbsp;</label></td>
      <td>
      <input type="file" name="arquivo5" id="arquivo5" value="" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td><input type="submit" value="Enviar" /></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1" />
</form>


</div>            
 <table class="listing" cellpadding="0" cellspacing="0" align="center">
<?php
if ($row_RSfotos['FOT_CODIGO']==""){
echo "<tr><td>Ainda não a fotos nesse álbum</td></tr>";
}
else{
$coluna=1;
 do{ 
if($coluna ==1){
	echo "<tr><td><a href='fotosantiga/".$row_RSfotos['FOT_CODIGO'].".JPG' >";
	echo  "<img src='fotosantiga/". $row_RSfotos['FOT_CODIGO'].".JPG' width='200' height='100' />" ;
	echo "</a>";
	echo "<a href='fotos-apaga.php?idfoto=".$row_RSfotos['FOT_CODIGO']."&&album=$idalbum'>";
	echo "<img src='img/hr.gif' />";
	echo "</a></td>";
	$coluna++;
}

elseif($coluna==2){
	$coluna++;
	echo"<td> <a href='fotosantiga/".$row_RSfotos['FOT_CODIGO'].".JPG' >";
	echo  "<img src='fotosantiga/". $row_RSfotos['FOT_CODIGO'].".JPG' width='200' height='100' />";
	echo "</a>";
	echo "<a href='fotos-apaga.php?idfoto=".$row_RSfotos['FOT_CODIGO']."&&album=$idalbum'>";
	echo "<img src='img/hr.gif' />";
	echo "</a></td>";
}
elseif($coluna==3){
	echo"<td><a href='fotosantiga/".$row_RSfotos['FOT_CODIGO'].".JPG' >";
	echo  "<img src='fotosantiga/". $row_RSfotos['FOT_CODIGO'].".JPG' width='200' height='100' />";
	echo "</a>";
	echo "<a href='fotos-apaga.php?idfoto=".$row_RSfotos['FOT_CODIGO']."&&album=$idalbum'>";
	echo "<img src='img/hr.gif' />";
	echo "</a></td></tr>";
	$coluna = 1;	
} 
 
  }while($row_RSfotos = mysql_fetch_assoc($RSfotos));
}

?>
</table>

</div>

</div>
            <div id="right-column">
                <strong class="h">SUPORTE</strong>
                <div class="box">O suporte tecnico funciona de segunda a sexta no horario de 9:30h as 18h pelo telefone:  (84)8759-6187 / (84)9675-2663 robertojuniorluiz16 @gmail.com</div>
<!--fim do conteudo-->
            </div>
        </div>
        <div id="footer"><p>&copy;COPYRIGHT <a href="http://twitter.com/jrnescau" target="_blank">Nescau</a> e <a href="http://twitter.com/JessuirCleydson" target="_blank">Jessuir</a> 2012. </p></div>
</div>
</body>
</html>
<?php
mysql_free_result($RSfotos);
?>
